package com.iplant.ams.service.po.dms.scada.alarm;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.iplant.ams.service.po.dms.DMSDeviceLedger;
import com.iplant.base.po.BasePO;
import com.iplant.base.po.enums.DBSchemas;
import com.iplant.base.utils.annotation.condition.DBCondition;
import com.iplant.base.utils.annotation.field.DBField;
import com.iplant.base.utils.annotation.join.DBJoin;
import com.iplant.base.utils.annotation.join.multi.DBJoinMulti;
import com.iplant.base.utils.annotation.po.DBBasePO;

import java.io.Serializable;
import java.util.Calendar;

@DBBasePO(TableName = "dms_device_alarm", Schemas = DBSchemas.AMS, CheckName = {"DeviceID"},
        Code = false, Name = false, Active = false, Comment = "设备当前状态",OrderBy="UpdateDate desc")
public class DMSDeviceCurrentAlarm extends BasePO implements Serializable {
    private static final long serialVersionUID = 1L;

    @DBCondition
    @DBField(name = "DeviceID",Description = "设备AssetNo")
    public String AssetNo = "";

    @DBCondition
    @DBField(name = "FaultID", Description = "设备报警编码")
    public String AlarmCode = "";


    @DBJoin(name = "Name", tableName = "dms_device_parameter", tableAsName = "param1",
            Schemas = DBSchemas.AMS, ConditionalJoin = "param1.DataClass=2  and param1.Code=t.FaultID")
    public String AlarmName = "";
    @DBJoin(name = "VariableName", tableName = "dms_device_parameter", tableAsName = "param1",
            Schemas = DBSchemas.AMS, ConditionalJoin = "param1.DataClass=2  and param1.Code=t.FaultID")
    public String AlarmVariableName = "";

    @DBCondition
    @DBJoin(name = "DataGrad", tableName = "dms_device_parameter", tableAsName = "param1",
            Schemas = DBSchemas.AMS, ConditionalJoin = "param1.DataClass=2  and param1.Code=t.FaultID")
    public int DataGrad = 0;

    @DBJoin(name = "ParameterDesc", tableName = "dms_device_parameter", tableAsName = "param1",
            Schemas = DBSchemas.AMS, ConditionalJoin = "param1.DataClass=2 and   param1.Code=t.FaultID")
    public String AlarmDesc = "";

    @DBJoin(name = "PositionID", tableName = "dms_device_parameter", tableAsName = "param1",
            Schemas = DBSchemas.AMS, ConditionalJoin = "param1.DataClass=2 and   param1.Code=t.FaultID")
    public int PositionID = 0;

    @DBJoinMulti(Name = "Name", TableName = "dms_position", Schemas = DBSchemas.AMS, MainTableField = "PositionID")
    public String PositionName = "";

    @DBCondition(CompareType = DBCondition.DBCompareType.geLe, ParamName = "UDStartTime", ParamName2 = "EndTime")
    @DBField
    public Calendar OccurTime = Calendar.getInstance();
    @DBCondition(CompareType = DBCondition.DBCompareType.geLe, ParamName = "StartTime", ParamName2 = "UDEndTime")
    @DBField
    public Calendar UpdateDate = Calendar.getInstance();


    public DMSDeviceAlarm CreateDeviceAlarm(DMSDeviceLedger wDMSDeviceLedger) {
        DMSDeviceAlarm wDeviceAlarm = new DMSDeviceAlarm();

        wDeviceAlarm.ID = this.ID;
        wDeviceAlarm.AssetNo = this.AssetNo;
        wDeviceAlarm.PositionID = this.PositionID;
        wDeviceAlarm.PositionName = this.PositionName;

        wDeviceAlarm.PositionText = this.PositionName;
        wDeviceAlarm.AlarmCode = this.AlarmCode;
        wDeviceAlarm.AlarmName = this.AlarmName;
        wDeviceAlarm.AlarmVariableName = this.AlarmVariableName;
        wDeviceAlarm.AlarmDesc = this.AlarmDesc;
        wDeviceAlarm.StatusTime = this.OccurTime;
        wDeviceAlarm.StatusTimeEnd = this.UpdateDate;
        wDeviceAlarm.EventType = 1;
        wDeviceAlarm.DataGrad=this.DataGrad;
        if (wDMSDeviceLedger != null) {
            wDeviceAlarm.DeviceNo = wDMSDeviceLedger.Code;
            wDeviceAlarm.DeviceName = wDMSDeviceLedger.Name;
            wDeviceAlarm.DeviceID = wDMSDeviceLedger.ID;
            wDeviceAlarm.ModelID = wDMSDeviceLedger.ModelID;
            wDeviceAlarm.ModelName = wDMSDeviceLedger.StandardModelName;
            wDeviceAlarm.ModelNo = wDMSDeviceLedger.StandardModelCode;
            wDeviceAlarm.DeviceType = wDMSDeviceLedger.DeviceTypeID;
            wDeviceAlarm.DeviceTypeName = wDMSDeviceLedger.DeviceTypeName;
            wDeviceAlarm.DeviceTypeCode = wDMSDeviceLedger.DeviceTypeCode;
            wDeviceAlarm.WorkShopID = wDMSDeviceLedger.WorkshopID;
            wDeviceAlarm.WorkShopName = wDMSDeviceLedger.WorkshopName;
            wDeviceAlarm.WorkShopCode = wDMSDeviceLedger.WorkshopCode;
            wDeviceAlarm.FactoryID = wDMSDeviceLedger.FactoryID;
            wDeviceAlarm.FactoryName = wDMSDeviceLedger.FactoryName;
            wDeviceAlarm.FactoryCode = wDMSDeviceLedger.FactoryCode;
            wDeviceAlarm.AreaID = wDMSDeviceLedger.WorkAreaID;
            wDeviceAlarm.AreaNo = wDMSDeviceLedger.WorkAreaCode;
            wDeviceAlarm.AreaName = wDMSDeviceLedger.WorkAreaName;
            wDeviceAlarm.ImageIcon = wDMSDeviceLedger.ImageIcon;
        }
        return wDeviceAlarm;
    }




    @JsonProperty("AssetNo")
    public String getAssetNo() {
        return AssetNo;
    }

    public void setAssetNo(String assetNo) {
        AssetNo = assetNo;
    }



    @JsonProperty("UpdateDate")
    public Calendar getUpdateDate() {
        return UpdateDate;
    }

    public void setUpdateDate(Calendar updateDate) {
        UpdateDate = updateDate;
    }

    @JsonProperty("AlarmCode")
    public String getAlarmCode() {
        return AlarmCode;
    }

    public void setAlarmCode(String alarmCode) {
        AlarmCode = alarmCode;
    }

    @JsonProperty("OccurTime")
    public Calendar getOccurTime() {
        return OccurTime;
    }

    public void setOccurTime(Calendar occurTime) {
        OccurTime = occurTime;
    }

    @JsonProperty("AlarmName")
    public String getAlarmName() {
        return AlarmName;
    }

    public void setAlarmName(String alarmName) {
        AlarmName = alarmName;
    }

    @JsonProperty("AlarmVariableName")
    public String getAlarmVariableName() {
        return AlarmVariableName;
    }

    public void setAlarmVariableName(String alarmVariableName) {
        AlarmVariableName = alarmVariableName;
    }

    @JsonProperty("DataGrad")
    public int getDataGrad() {
        return DataGrad;
    }

    public void setDataGrad(int dataGrad) {
        DataGrad = dataGrad;
    }

    @JsonProperty("AlarmDesc")
    public String getAlarmDesc() {
        return AlarmDesc;
    }

    public void setAlarmDesc(String alarmDesc) {
        AlarmDesc = alarmDesc;
    }

    @JsonProperty("PositionID")
    public int getPositionID() {
        return PositionID;
    }

    public void setPositionID(int positionID) {
        PositionID = positionID;
    }

    @JsonProperty("PositionName")
    public String getPositionName() {
        return PositionName;
    }

    public void setPositionName(String positionName) {
        PositionName = positionName;
    }
}
